<?php

namespace App\HttpController;

use App\Service\CallbackService;
use EasySwoole\HttpAnnotation\AnnotationTag\Api;
use EasySwoole\HttpAnnotation\AnnotationTag\Method;
use EasySwoole\Log\Logger;
use EasySwoole\Mysqli\Exception\Exception;
use EasySwoole\Pay\Exceptions\InvalidArgumentException;
use EasySwoole\Pay\Exceptions\InvalidSignException;
use Throwable;

class Callback extends BaseController
{
    /**
     * @Api(name="微信支付回调", path="/callback/mxwepay", version="1.0.0")
     * @Method(allow={GET,POST})
     * @throws Exception
     * @throws Exception
     * @throws InvalidArgumentException
     * @throws InvalidSignException
     * @throws Throwable
     */
    public function mxwepay(): bool
    {
        $data = $this->request()->getBody()->__toString();
        $res = CallbackService::getInstance()->mxwepay($data);
        if ($res['result']) {
            $res = \EasySwoole\Pay\WeChat\WeChat::success();//成功响应
        } else {
            $res = \EasySwoole\Pay\WeChat\WeChat::fail();//失败响应
        }
        $this->response()->withAddedHeader('Content-type', "application/xml");
        return $this->response()->write($res);
    }
}